package com.IO流.处理流.Exercise练习;

import java.io.*;
import java.nio.charset.StandardCharsets;

@SuppressWarnings("all")
public class E02 {
    /**
     * 用BufferedReader读取文本文件，为每行添加行号，输出到屏幕
     */
    public static void main(String[] args) throws IOException {
        String filePath = "D:/JAVA_test/bufferedExercise01.java";  ///路径
        File file = new File(filePath);   ///文件
//        BufferedReader br = new BufferedReader(new FileReader(file));  ///处理流
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
        ///如果文件是GBK编码，直接读取会乱码，所以用到转换流，根据文件形式，改一下编码就可以了
        String readLine = "";  ///读取到的字符串存放变量
        int i = 0;  ///行号
        while((readLine = br.readLine()) != null){  /// 不为空
            System.out.println((++i) + "  "+readLine);
        }
        br.close();  ///关闭




    }
}
